package com.moon.admin.tools.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.moon.admin.tools.domain.TableListQueryVO;
import com.moon.admin.tools.entity.GenTable;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 业务 数据层
 *
 * @author ninglong
 */
@Mapper
public interface GenTableMapper extends BaseMapper<GenTable> {


    /**
     * 查询据库列表
     *
     * @param tableNames 表名称组
     * @return 数据库表集合
     */
    List<GenTable> selectDbTableListByNames(String[] tableNames);

    @Select("<script>"+
            "select table_name as tableName, table_comment as tableComment, create_time as createTime, update_time as updateTime from information_schema.tables where table_schema = (select database()) AND table_name NOT LIKE 'act_%' AND table_name NOT LIKE 'gen_%' " +
            "<if test=\"query.tableName != null and query.tableName != ''\">" +
            "AND lower(table_name) like lower(concat('%', #{query.tableName}, '%'))" +
            "</if>" +
            "<if test=\"query.tableComment != null and query.tableComment != ''\">" +
            "AND lower(table_comment) like lower(concat('%', #{query.tableComment}, '%'))" +
            "</if>" +
            "</script>")
    /**
     * 查询据库列表
     *
     * @param genTable 业务信息
     * @return 数据库表集合
     */
    List<GenTable> selectDbTableList(IPage<GenTable> page, @Param("query") TableListQueryVO tableListQueryVO);
}
